<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>构造函数</title>
	</head>
	<body>
		<script type="text/javascript">
			//通过构造函数：创建出一些具有相同特征的对象
			
			//1.内置构造函数
			var obj1=new Object();
			var str1=new String("hi");
			console.log(obj1.constructor);//f Object(){[native code]}
			console.log(str1.constructor);//f String(){[bative code]}
			//若不用构造函数，定义2个具有相同属性的对象
			var o1={
				"name":"Lily",
				"age":14,
				sayHi:function(){console.log("Holle");}
			};
			var o2={
				"name":"Tom",
				"age":15,
				sayHi:function(){console.log("Holle");}
			};
			//2.自定义构造函数
			function Person(name,age){
				this.name=name;
				this.age=age;
				this.sayHi=function(){console.log("hello");};
			}
			var p1=new Person('zhangsan',20);
			var p2=new Person('lisi',24);
			console.log(p1.constructor);
			console.log(p1.constructor==p2.constructor);
		</script>
	</body>
</html>
